import HTTP from '@/plugins/axios'
import { api } from '@/ts/enum'
import { dealRes, pageList } from '@/ts/type'
import { GoodDtos, Goods, Type } from '@/ts/type/Goods'

const GoodsService = class GoodsService {
  static getAllInfo(page: number, size: number) {
    return HTTP.get<dealRes<pageList<GoodDtos>>>(`/${api.GoodsApi}/${page}/${size}`)
  }

  static postQuery(page: number, size: number, data: Type) {
    return HTTP.post<dealRes<pageList<GoodDtos>>>(`/${api.GoodsApi}/${page}/${size}`, data)
  }

  static postGoods(data: GoodDtos) {
    return HTTP.post<dealRes<string>>(`/${api.GoodsApi}`, data)
  }

  static getOptions() {
    return HTTP.get<dealRes<Type[]>>(`/${api.GoodsApi}/option`)
  }

  static getById(id: number) {
    return HTTP.get<dealRes<Goods>>(`/${api.GoodsApi}/${id}`)
  }

  static updateGoods(data: Goods) {
    return HTTP.put<dealRes<string>>(`/${api.GoodsApi}`, data)
  }

  static deleteById(id: number) {
    return HTTP.delete<dealRes<string>>(`/${api.GoodsApi}/${id}`)
  }
}

export default GoodsService